package com.itheima.app.controller;

import com.itheima.app.manager.MovementManager;
import com.itheima.domain.mongo.Movement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class MovementController {
    @Autowired
    private MovementManager movementManager;

    @PostMapping("/movements")
    public ResponseEntity saveMovements(Movement movement, MultipartFile[] imageContent) throws IOException {
        return movementManager.saveMovement(movement, imageContent);
    }

    @GetMapping("/movements/all")
    public ResponseEntity findMyMovement(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize,
            Long userId) {
        return movementManager.findMyMovement(page, pagesize, userId);
    }

//查看朋友动态
    @GetMapping("/movements")
    public ResponseEntity findFriendMovement(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) {
        return movementManager.findFriendMovement(page, pagesize);
    }

    //查询推荐动态
    @GetMapping("/movements/recommend")
    public ResponseEntity findRecommendMovement(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) {
        return movementManager.findRecommendMovement(page, pagesize);
    }

    //点赞
    @GetMapping("/movements/{publishId}/like")
    public ResponseEntity movementLike(
            @PathVariable String publishId) {
        System.out.println("movementLikeController---" + publishId);
        return movementManager.movementLike(publishId);
    }

    //取消点赞
    @GetMapping("/movements/{publishId}/dislike")
    public ResponseEntity movementDislike(
            @PathVariable String publishId
    ) {
        return movementManager.movementDislike(publishId);
    }

    //单条动态
    @GetMapping("/movements/{publishId}")
    public ResponseEntity findMovementsById(
            @PathVariable String publishId
    ) {
        return movementManager.findMovementsById(publishId);
    }

    @GetMapping("/comments")
    public ResponseEntity findCommentByPage(
            String movementId,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) {
        System.out.println("findCommentByPage" + movementId);
        return movementManager.findCommentByPage(movementId, page, pagesize);
    }


    @PostMapping("/comments")
    public ResponseEntity saveComment(@RequestBody Map<String, String> map) {
        String movementId = map.get("movementId");
        String content = map.get("comment");
        return movementManager.saveComment(movementId, content);
    }

    //喜欢(id为动态id)
    @GetMapping("/movements/{publishId}/love")
    public ResponseEntity movementLove(
            @PathVariable String publishId) {
        System.out.println("movementLikeController---" + publishId);
        return movementManager.movementLove(publishId);
    }
    //取消喜欢(id为动态id)
    @GetMapping("/movements/{publishId}/unlove")
    public ResponseEntity movementUnlove(
            @PathVariable String publishId
    ) {
        return movementManager.movementUnlove(publishId);
    }




}
